<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2019/3/13
 * Time: 14:32
 */

namespace app\admin\controller;


use think\Db;
use think\Request;

class Toprefresh extends Base
{
    /**
     * @return mixed|\think\response\Json
     * 展示
     */
    public function index(){
        if(request()->isAjax ()){
            $Nowpage = input('page') ? input('page'):1;
            $limits = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::name('top_bag')->count();
            $lists = Db::name('top_bag')
                ->page($Nowpage,$limits)
                ->select ();
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch('toprefresh/index');
    }
    
    /**
     * @return mixed|\think\response\Json
     * 编辑价格
     */
    public function bagEdit(){
        if(Request::instance()->isPost()){
            $t_b_id = input('t_b_id');
            $t_b_price = input('t_b_price');
            $update = [
                't_b_price' => $t_b_price,
                't_b_update_time' => date('Y-m-d H:i:s')
            ];
            if($t_b_id == 3 || $t_b_id == 4){
                $update['t_b_iosid'] = input('t_b_iosid');
            }
            $res = Db::table('up_top_bag')->where('t_b_id', $t_b_id)->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $id = input('id');
        $info = Db::table('up_top_bag')->where('t_b_id', $id)->find();
        $this->assign('info', $info);
        return $this->fetch('toprefresh/bagedit');
    }
}